package com.atguigu.lease.web.app.interceptors;

import com.atguigu.lease.common.jwt.JwtUtil;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.common.springmvc.LeaseException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.util.ObjectUtils;
import org.springframework.web.servlet.HandlerInterceptor;


public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        //获取token
        String token = request.getHeader("access_token");
        //判断是不是空的
        if (ObjectUtils.isEmpty(token)) {
            throw new LeaseException(ResultCodeEnum.APP_LOGIN_AUTH);
        }
        //不是空的
        JwtUtil.parseToken(token);
        return true;
    }
}
